#include "../ui.h"
#include "../ui_helpers.h"
#include "ui_comp.h"

uint32_t LV_EVENT_GET_COMP_CHILD;

typedef struct
{
    uint32_t child_idx;
    lv_obj_t *child;
} ui_comp_get_child_t;

lv_obj_t *ui_comp_get_child(lv_obj_t *comp, uint32_t child_idx)
{
    ui_comp_get_child_t info;
    info.child = NULL;
    info.child_idx = child_idx;
    lv_event_send(comp, LV_EVENT_GET_COMP_CHILD, &info);
    return info.child;
}

void get_component_child_event_cb(lv_event_t *e)
{
    lv_obj_t **c = lv_event_get_user_data(e);
    ui_comp_get_child_t *info = lv_event_get_param(e);
    info->child = c[info->child_idx];
}

void del_component_child_event_cb(lv_event_t *e)
{
    lv_obj_t **c = lv_event_get_user_data(e);
    lv_mem_free(c);
}
